import Vue from "vue";
import router from "./router";
// import store from './store'
import App from "./App.vue";
import axios from "axios";
import VueAxios from "vue-axios";
import VueLazyLoad from "vue-lazyload";
import VueCookie from "vue-cookie";
import store from "./store";
// 引入element-ui
import {
    Message
} from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
// import env from "./env"
// mock
// 定义开关
// const mock = false;
// if (mock) {
//     require('./mock/api')
// }
// 根据前端的跨域方式做调整
axios.defaults.baseURL = "/api";
axios.defaults.timeout = 8000;
// 拦截器
// axios.defaults.baseURL = env.baseURL;
axios.interceptors.response.use(
    function(response) {
        // console.log(response.data);
        let res = response.data;
        // 获取地址栏地址
        let path = location.hash;
        // 根据环境变量来获取不同的请求地址
        // 没错误返回0  错误·拦截
        if (res.status == 0) {
            return res.data;
        } else if (res.status == 10) {
            if (path != "#/index") {
                window.location.href = "/#/login";
            }
            return Promise.reject(res);
            // window.location.href = '/#/login'
        } else {
            this.$message.warning(res.msg);
            return Promise.reject(res);
        }
    },
    (error) => {
        let res = error.response;
        this.$message.error(res.data.message);
        return Promise.reject(error);
    }
);
Vue.use(VueCookie);
Vue.use(VueLazyLoad, {
    loading: "/imgs/loading-svg/loading-bars.svg",
});
Vue.prototype.$message = Message;
Vue.use(VueAxios, axios);
Vue.config.productionTip = false;
//

new Vue({
    store,
    router,
    render: (h) => h(App),
}).$mount("#app");